﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using Thor.Common;
using Thor.Domain;

namespace Thor.Repository.Azure.Table
{
    public abstract class TableRepositoryBase : IRepository
    {
        #region Constants

        private const string APPLICATIONNAME = "ApplicationName";
        private const string CONNECTIONSTRING = "ConnectionString";

        #endregion

        #region Constructors

        public TableRepositoryBase(Dictionary<string, object> repositoryParameters)
        {
            RepositoryParameters = repositoryParameters;
        }

        #endregion

        #region Properties

        public CloudStorageAccount StorageAccount
        {
            get
            {
                if (RepositoryParameters[CONNECTIONSTRING] != null)
                    return CloudStorageAccount.FromConfigurationSetting(Convert.ToString(RepositoryParameters[CONNECTIONSTRING]));
                else
                    return null;
            }
        }

        public string ApplicationName
        {
            get
            {
                if(RepositoryParameters[APPLICATIONNAME] != null)
                    return Convert.ToString(RepositoryParameters[APPLICATIONNAME]);
                else
                    return string.Empty;
            }
            set
            {
                if (RepositoryParameters[APPLICATIONNAME] != null)
                    RepositoryParameters[APPLICATIONNAME] = value;
            }
        }

        #endregion

        #region IRepository Members

        public Dictionary<string, object> RepositoryParameters { get; set; }

        #endregion
    }
}
